package com.scan.record.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.uuid.UUID;
import com.scan.record.domain.ScanRecordInfoStat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.scan.record.mapper.ScanRecordInfoMapper;
import com.scan.record.domain.ScanRecordInfo;
import com.scan.record.service.IScanRecordInfoService;

/**
 * 扫码信息记录Service业务层处理
 * 
 * @author ysz
 * @date 2023-04-22
 */
@Service
public class ScanRecordInfoServiceImpl implements IScanRecordInfoService 
{
    @Autowired
    private ScanRecordInfoMapper scanRecordInfoMapper;

    /**
     * 查询扫码信息记录
     * 
     * @param scanId 扫码信息记录主键
     * @return 扫码信息记录
     */
    @Override
    public ScanRecordInfo selectScanRecordInfoByScanId(String scanId)
    {
        return scanRecordInfoMapper.selectScanRecordInfoByScanId(scanId);
    }

    /**
     * 查询扫码信息记录列表
     * 
     * @param scanRecordInfo 扫码信息记录
     * @return 扫码信息记录
     */
    @Override
    public List<ScanRecordInfo> selectScanRecordInfoList(ScanRecordInfo scanRecordInfo)
    {
        return scanRecordInfoMapper.selectScanRecordInfoList(scanRecordInfo);
    }

    /**
     * 查询扫码信息记录列表-聚合
     *
     * @param dateCycle 时间周期
     * @return 扫码信息记录集合
     */
    public List<ScanRecordInfoStat> selectScanRecordInfoListStat(String dateCycle) {
        if ("all".equals(dateCycle)) {
            return scanRecordInfoMapper.selectScanRecordInfoListStatAll();
        } else if ("day".equals(dateCycle)) {
            dateCycle = "%Y-%m-%d";
        } else if ("month".equals(dateCycle)) {
            dateCycle = "%Y-%m";
        }
        return scanRecordInfoMapper.selectScanRecordInfoListStat(dateCycle);
    }

    /**
     * 新增扫码信息记录
     * 
     * @param scanRecordInfo 扫码信息记录
     * @return 结果
     */
    @Override
    public int insertScanRecordInfo(String scanBelong)
    {
        ScanRecordInfo scanRecordInfo = new ScanRecordInfo();
        scanRecordInfo.setScanId(UUID.fastUUID().toString());
        scanRecordInfo.setScanBelong(scanBelong);
        scanRecordInfo.setScanTime(new Date());
        return scanRecordInfoMapper.insertScanRecordInfo(scanRecordInfo);
    }

    /**
     * 修改扫码信息记录
     * 
     * @param scanRecordInfo 扫码信息记录
     * @return 结果
     */
    @Override
    public int updateScanRecordInfo(ScanRecordInfo scanRecordInfo)
    {
        return scanRecordInfoMapper.updateScanRecordInfo(scanRecordInfo);
    }

    /**
     * 批量删除扫码信息记录
     * 
     * @param scanIds 需要删除的扫码信息记录主键
     * @return 结果
     */
    @Override
    public int deleteScanRecordInfoByScanIds(String[] scanIds)
    {
        return scanRecordInfoMapper.deleteScanRecordInfoByScanIds(scanIds);
    }

    /**
     * 删除扫码信息记录信息
     * 
     * @param scanId 扫码信息记录主键
     * @return 结果
     */
    @Override
    public int deleteScanRecordInfoByScanId(String scanId)
    {
        return scanRecordInfoMapper.deleteScanRecordInfoByScanId(scanId);
    }
}
